package task;

import machinery.Machinery;
import java.util.ArrayList;
import java.util.List;

/**
 * 任务管理器类
 */
public class TaskManager {
    private List<Task> tasks;
    
    public TaskManager() {
        this.tasks = new ArrayList<>();
    }
    
    public void createTask(String taskName, Machinery machinery) {
        Task task = new Task(taskName, machinery);
        tasks.add(task);
        System.out.println("创建任务: " + taskName + ", 分配给: " + machinery.getName());
        task.execute();
    }
    
    public void completeTask(Task task) {
        if (tasks.contains(task)) {
            task.complete();
        }
    }
    
    public void failTask(Task task, String reason) {
        if (tasks.contains(task)) {
            task.fail(reason);
        }
    }
    
    public List<Task> getTasks() {
        return new ArrayList<>(tasks);
    }
    
    public void clearTasks() {
        tasks.clear();
        System.out.println("清空所有任务");
    }
} 